<h2><?php  __('Grupo');?></h2>
<div align="left"><?php $session->flash(); ?></div>
<div class="grupos view">    
    <dl><?php $i = 0; $class = ' class="altrow"';?>
            <dt<?php if ($i % 2 == 0) echo $class;?>><?php __('Codigo'); ?></dt>
            <dd<?php if ($i++ % 2 == 0) echo $class;?>>
                    <?php echo $grupo['Grupo']['codigo']; ?>
                    &nbsp;
            </dd>
            <dt<?php if ($i % 2 == 0) echo $class;?>><?php __('Nombre'); ?></dt>
            <dd<?php if ($i++ % 2 == 0) echo $class;?>>
                    <?php echo $grupo['Grupo']['descripcion']; ?>
                    &nbsp;
            </dd>
            <dt<?php if ($i % 2 == 0) echo $class;?>><?php __('Descripción'); ?></dt>
            <dd<?php if ($i++ % 2 == 0) echo $class;?>>
                    <?php echo $grupo['Grupo']['observaciones']; ?>
                    &nbsp;
            </dd>
    </dl>
<fieldset id="add">
<?php echo $form->create(null, array('url'=>'/Grupos/view/'.$grupo['Grupo']['id'], 'id'=>'FormAdd'));?>
    <table cellpadding="3" style="width: 100%">
        <tr>
            <td width="80px">
                <?php echo $form->select('ArosAco.action',
                        array(
                            '1'=>'Permitir',
                            '-1'=>'Denegar'),
                        1, null, false);?>
            </td>
            <td width="140px">
                <?php echo $form->input('ArosAco.aro_id', array(
                    'type'=>'hidden',
                    'value'=>$grupo['Grupo']['id']));?>
                <?php echo $form->input('ArosAco.aco_id', array(
                    'label'=>false,
                    'div'=>false));?>
            </td>
            <td width="80px">Todos
                <?php echo $form->input('ArosAco.all', array(
                    'label'=>false,
                    'div'=>false,
                    'name'=>'data[ArosAco][all]',
                    'value'=>'*',
                    'type'=>'checkbox'));?>
            </td>
            <td width="80px">Adicionar
                <?php echo $form->input('ArosAco.create', array(
                    'label'=>false,
                    'div'=>false,
                    'name'=>'data[ArosAco][commands][create]',
                    'value'=>true,
                    'type'=>'checkbox'));?>
            </td>
            <td width="80px">Visualizar
                <?php echo $form->input('ArosAco.read', array(
                    'label'=>false,
                    'div'=>false,
                    'name'=>'data[ArosAco][commands][read]',
                    'value'=>true,
                    'type'=>'checkbox'));?>
            </td>
            <td width="80px">Editar
                <?php echo $form->input('ArosAco.update', array(
                    'label'=>false,
                    'div'=>false,
                    'name'=>'data[ArosAco][commands][update]',
                    'value'=>true,
                    'type'=>'checkbox'));?>
            </td>
            <td>Eliminar
                <?php echo $form->input('ArosAco.delete', array(
                    'label'=>false,
                    'div'=>false,
                    'name'=>'data[ArosAco][commands][delete]',
                    'value'=>true,
                    'type'=>'checkbox'));?>
            </td>
            <td></td>
        </tr>
        <tr>
            <td colspan="8">
                <?php echo $form->submit('Guardar', array('div'=>false,'style'=>'', 'class'=>'btnsave'));?>
            </td>
        </tr>
    </table>
    <?php echo $form->end();?>
    </fieldset><p/>
    <?php echo $form->create(null, array('action'=>'processPermissions', 'id'=>'FormDelete'));?>
    <?php echo $form->hidden('Grupo.id',array('value'=>$grupo['Grupo']['id']))?>
    <table cellpadding="3">
        <tr>
            <th width="20px">&nbsp;</th>
            <th>Objeto</th>
            <th>Adicionar</th>
            <th>Visualizar</th>
            <th>Editar</th>
            <th>Eliminar</th>
        </tr>
    <?php $i = 0;
          foreach($permissions as $p):
                $class = null;
                if ($i++ % 2 == 0) {
                        $class = ' class="altrow"';
                }?>
        <tr<?php echo $class;?>>
            <td>
                <?php echo $form->input('ArosAco.id', array(
                    'label'=>false,
                    'div'=>false,
                    'id'=>'ArosAcosId'.$i,
                    'name'=>"data[Permissions][$i][id]",
                    'value'=>$p['ArosAco']['id'],
                    'type'=>'checkbox'));?></td>
            <td>
                <?php if (!empty($p['Aco']['parent_id'])) {
                        if (!empty($p['Aco']['Aco']['parent_id']))
                            echo $p['Aco']['Aco']['Aco']['alias'].'/';
                        echo $p['Aco']['Aco']['alias'].'/';
                    }?>
                <?php echo $p['Aco']['alias'];?>
            </td>
            <td align="center"><?php echo $p['ArosAco']['_create']==1?'Si':'No';?></td>
            <td align="center"><?php echo $p['ArosAco']['_read']==1?'Si':'No';?></td>
            <td align="center"><?php echo $p['ArosAco']['_update']==1?'Si':'No';?></td>
            <td align="center"><?php echo $p['ArosAco']['_delete']==1?'Si':'No';?></td>
        </tr>
    <?php endforeach;?>
    <?php if($i == 0):?>
        <tr>
            <td colspan="7">No existen permisos asociados</td>
        </tr>
    <?php endif;?>
    </table>
    <?php echo $form->submit('Eliminar', array(
        'div' => false,
        'class' => 'btnerase',
        'value'=>true,
        'name'=>'delete'));?>
    <?php echo $form->end();?>
    <div class="actions">
        <p>
            <?php echo $html->link(__('Volver', true), array('action' => 'index'), array('class'=>'lnkbutton btnback')); ?>
            <?php echo $html->link(__('Nuevo', true), array('action' => 'add'), array('class'=>'lnkbutton btnnew')); ?>
            <?php echo $html->link(__('Editar', true), array('action' => 'edit', $grupo['Grupo']['id']), array('class'=>'lnkbutton btnedit')); ?>
            <?php echo $html->link(__('Eliminar', true), array('action' => 'delete', $grupo['Grupo']['id']), array('class'=>'lnkbutton btnerase'), sprintf(__('Are you sure you want to delete # %s?', true), $grupo['Grupo']['codigo'])); ?>
            <?php echo $html->link(__('Empresas', true), array('action' => 'addEmpresa', $grupo['Grupo']['id']), array('class'=>'lnkbutton btnnewaccount', 'title'=>'Asociar Empresas')); ?>
            <?php echo $html->link(__('Depositos', true), array('action' => 'addCentroDist', $grupo['Grupo']['id']), array('class'=>'lnkbutton btnnewaccount', 'title'=>'Asociar Centros de Distribucion')); ?>
        </p>
    </div>
</div>
<script type="text/javascript">
    $(function(){
        $('#FormDelete .btnerase').unbind('click');
        $('#ArosAcoAll').attr('checked', false);
        $('#ArosAcoAll').click(function(){
            if ($(this).is(':checked')){
                $("#add input[type=checkbox]").each(function() {
                    $(this).attr('checked', false);
                    $(this).attr('disabled', true);
                });
                $(this).attr('checked', true);
                $(this).attr('disabled', false);
            } else {
                $("#add input[type=checkbox]").each(function() {
                    $(this).attr('checked', false);
                    $(this).attr('disabled', false);
                });
            }
        });
    });
</script>